/**
 * @(#)TaskManagerInstance.java        1.0 2/21/12
 * 
 * Copyright (c) 2012 public static droid main
 * Georgia Institute of Technology, Atlanta, GA
 * All rights reserved.
 */

package edu.gatech.oad.publicstaticdroidmain.taskmanager.ui;

import android.app.Application;
import edu.gatech.oad.publicstaticdroidmain.taskmanager.model.LoginManager;
import edu.gatech.oad.publicstaticdroidmain.taskmanager.model.TaskManager;
import edu.gatech.oad.publicstaticdroidmain.taskmanager.persistence.DataSourceInterface;
import edu.gatech.oad.publicstaticdroidmain.taskmanager.persistence.TaskManagerSQLiteDatabase;

/**
 * A singleton that holds a single instance of a TaskManager object
 * and a single instance of a LoginManager object. This class contains 
 * static methods for accessing those instances. The purpose of this class 
 * is to enable all Activities in the GUI to access the same TaskManager and 
 * LoginManager without having to keep passing it around.
 * 
 * @version 1.0 Feb 21 2012
 * @author Raheel Merali
 */
public class TaskManagerApplication extends Application {
    private static TaskManager TASK_MANAGER;
    private static LoginManager LOGIN_MANAGER;
    
    @Override
    public void onCreate() {
	//the db that will be used by the LoginManager
	DataSourceInterface db = new TaskManagerSQLiteDatabase(getApplicationContext());
	db.open();
	
	LOGIN_MANAGER = new LoginManager(db);
    }
    
    /**
     * Sets the instance of TaskManager to the specified TaskManager.
     *
     * @param newTaskManager the new instance of TaskManager
     */
    public static void setTaskManager(TaskManager newTaskManager) {
	TASK_MANAGER = newTaskManager;
    }
    
    /**
     * Returns the current TaskManager instance.
     *
     * @return the current instance of TaskManager
     */
    public static TaskManager getTaskManager() {
	return TASK_MANAGER;
    }
    
    /**
     * Returns the current LoginManager instance.
     *
     * @return the current instance of LoginManager
     */
    public static LoginManager getLoginManager() {
	return LOGIN_MANAGER;
    }
}
